package com.nkzy.controller;

import com.nkzy.pojo.Address;
import com.nkzy.pojo.User;
import com.nkzy.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/users")
public class UserController {

    @Autowired
    private UserService userService;

    @PostMapping
    public int insertUser(@RequestBody User user) {
        return userService.insertUser(user);
    }

    @DeleteMapping("/{id}")
    public int deleteUserById(@PathVariable Long id) {
        return userService.deleteUserById(id);
    }

    @PutMapping
    public int updateUser(@RequestBody User user) {
        return userService.updateUser(user);
    }

    @GetMapping("/{id}")
    public User selectUserById(@PathVariable Long id) {
        return userService.selectUserById(id);
    }

    @GetMapping
    public List<User> selectAllUsers() {
        return userService.selectAllUsers();
    }

    @GetMapping("/ids")
    public List<User> selectUsersByIds(@RequestParam List<Long> ids) {
        return userService.selectUsersByIds(ids);
    }

    @DeleteMapping("/address/{id}")
    public void deleteAddressById(@PathVariable Long id) {
        userService.deleteAddressById(id);
    }

    @PostMapping("/address")
    public void insertAddress(@RequestBody Address address) {
        userService.insertAddress(address);
    }

    @GetMapping("/address/all")
    public boolean selectAllAddress() {
        return userService.selectAllAddress();
    }

    @GetMapping("/address/{id}")
    public Address selectAddressById(@PathVariable Long id) {
        return userService.selectAddressById(id);
    }
}